package org.sjs.dreamfly.common.util

import android.net.Uri

object UriUtils {
    fun removeHost(url: String?): String? {
        if (url == null) return null
        Uri.parse(url)?.host?.let {
            url.split(it).let { list ->
                if (list.size > 1) {
                    return list[1]
                }
            }
        }
        return url
    }



    fun extractQueryParams(url: String): Map<String, String> {
        val queryParams = mutableMapOf<String, String>()
        val queryStartIndex = url.indexOf('?')
        if (queryStartIndex != -1) {
            val query = url.substring(queryStartIndex + 1)
            val pairs = query.split("&")
            pairs.forEach { pair ->
                val splitPair = pair.split("=")
                val key = splitPair[0]
                val value = splitPair.getOrElse(1) { "" }
                queryParams[key] = value
            }
        }
        return queryParams
    }
}